package ThreadPool.chapter3;

import java.util.concurrent.TimeUnit;

public class NoVisibility3 {

    private static  boolean flag;

    private static int number;

    public static class readThread extends Thread {
        @Override
        public void run() {
            while(!flag){
                // 线程让步,同级别线程抢到cpu时间片的几率是一样的
                Thread.yield();
            }
            System.out.println(number);
        }
    }


    public static void main(String[] args) throws InterruptedException {
        new readThread().start();
        flag = true;
        TimeUnit.MILLISECONDS.sleep(20);
        number = 42;
    }

}
